﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 测试提交
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class submitDetail : problemView<submitDetail>
    {
        /// <summary>
        /// 默认空集合
        /// </summary>
        private static readonly list<diantou.dataAccess.judgeItem.userJudgeItem> nullJudgeItems = new list<diantou.dataAccess.judgeItem.userJudgeItem>();
        /// <summary>
        /// 测试提交
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.contestJudge judge;
        /// <summary>
        /// 测试提交
        /// </summary>
        private diantou.dataAccess.contestJudge contestJudge
        {
            get { return judge; }
        }
        /// <summary>
        /// 用户相关提交
        /// </summary>
        private userJudge userJudge
        {
            get { return new userJudge { Judge = judge, UserId = currentUser == null ? 0 : currentUser.Id, IsAdmin = currentUser != null && currentUser.Permission == dataModel.user.permission.Admin }; }
        }
        /// <summary>
        /// 测试记录集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.judgeItem.userJudgeItem[] judgeItems;
        /// <summary>
        /// 
        /// </summary>
        private list<diantou.dataAccess.judgeItem.userJudgeItem> leftItems
        {
            get
            {
                if (judgeItems.length() == 0) return nullJudgeItems;
                return new list<diantou.dataAccess.judgeItem.userJudgeItem>(judgeItems, 0, (judgeItems.Length + 1) >> 1, true);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        private list<diantou.dataAccess.judgeItem.userJudgeItem> rightItems
        {
            get
            {
                if (judgeItems.length() == 0) return nullJudgeItems;
                int start = (judgeItems.Length + 1) >> 1;
                return new list<diantou.dataAccess.judgeItem.userJudgeItem>(judgeItems, start, judgeItems.Length - start, true);
            }
        }
        /// <summary>
        /// 程序内容
        /// </summary>
        private string programContent
        {
            get
            {
                if (currentUser == null) return null;
                return diantou.dataAccess.tcpCall.contestJudge.getProgramContent(judge.Id, currentUser.Id);
            }
        }
        /// <summary>
        /// 最后一个测试编号
        /// </summary>
        private int testId;
        ///// <summary>
        ///// 是否自己
        ///// </summary>
        //private bool isSelf
        //{
        //    get
        //    {
        //        return judge.UserId == currentUser.Id;
        //    }
        //}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="judgeId"></param>
        /// <returns></returns>
        protected override bool loadView(int judgeId)
        {
            if (judgeId == 0)
            {
                checkSearchEngine(diantou.dataModel.path.pub.Default.ContestListPath, webConfig.NotFound404);
                return false;
            }
            if (currentUser != null && (judge = diantou.dataAccess.tcpCall.contestJudge.Get(judgeId)) != null)
            {
                problem = diantou.dataAccess.clientCache.Problem[judge.ProblemId];
                int point = Math.Max(diantou.dataAccess.clientCache.ContestProblem[new diantou.dataModel.contestProblem.primaryKey { ContestId = problem.ContestId, ProblemId = problem.Id }], 0);
                if (problem.BasePoint != point) (problem = problem.Clone()).BasePoint = point;
                contest = diantou.dataAccess.clientCache.Contest[judge.ContestId];
                judgeItems = diantou.dataAccess.tcpCall.judgeItem.getContestJudge(judgeId, currentUserId, out testId);
                return true;
            }
            AjaxResponse(webConfig.NotFound404);
            return false;
        }
    }
}
